home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / SW Demo / Demo Source / PrintLoop.c < prev    next >
Encoding:
Text File  |  1994-10-07  |  3.9 KB  |  154 lines  |  [TEXT/MPCC]

  1. // ----------------------------------------------------------------------------------
  2. // PrintLoop.c
  3. // ----------------------------------------------------------------------------------
  4. // Handles all printing
  5. //
  6. // This demo is copywrite 1994 by LexTek Internation.  Feel free to use it for
  7. // whatever purpose you wish.  The SpellWright Library may not be copied or 
  8. // distributed, except when linked to your application that adds significant features
  9. // to the code.  ie. you can't take the library, make a new library and sell it.  You
  10. // can, however, use it without royalties in applications or other such projects.
  11. //
  12. // LexTek International
  13. // 2255 N. University Parkway, Suit 15
  14. // Provo, UT 84604
  15. // (801) 375.8332  Phone
  16. // (801) 375.7654  Fax 
  17. //
  18. // ----------------------------------------------------------------------------------
  19. // History:
  20. //    8/26/94        Clark Goble    Original (Doesn't do much right now)
  21. //
  22.  
  23. #include "Printing.h"
  24.  
  25. pascal void PrintIdleProc(void);
  26. void PrintWindow(void);
  27.  
  28.  
  29. // ----------------------------------------------------------------------------------
  30.  
  31. extern void ErrMsgCode(Str255 msg, short code);
  32.  
  33. // ----------------------------------------------------------------------------------
  34. // PrintIdleProc
  35. // ----------------------------------------------------------------------------------
  36. // Callback routine for printing.
  37.  
  38. pascal void PrintIdleProc( void )
  39. {
  40.     short    err;
  41.     
  42.     err = PrError();
  43.  
  44.     // spin cursor here
  45.         
  46.     if(err) {
  47.         InitCursor();        // restore cursor to arrow
  48.         
  49.         ErrMsgCode("\pI'm in the printing idle proc.",err);
  50.     }
  51. }
  52.  
  53.  
  54. // ----------------------------------------------------------------------------------
  55. // PrintWindow
  56. // ----------------------------------------------------------------------------------
  57. // Prints a window.  We use a goto to correctly handle printer closing.  I probably
  58. // should clean this up later, but for now I'm just more or less copying Apple's
  59. // code.
  60.  
  61. void PrintWindow( void )
  62. {
  63.     static PrIdleUPP PrintIdleProcUPP;
  64.     THPrint        PrinterInfo;
  65.     TPPrPort    printPort;
  66.     short        err;
  67.     TPrStatus    PrinterStat;
  68.  
  69.     PrinterInfo = (THPrint)NewHandle(sizeof(TPrint));
  70.     
  71.     if(!PrinterInfo) {
  72.         ErrMsgCode("\pAllocating TPrint failed.",0);
  73.         return;  
  74.     }
  75.     
  76.     PrOpen();    // open the printer
  77.     if((err = PrError()) != 0) 
  78.     {
  79.         ErrMsgCode("\p PrOpen failed.",err);
  80.         goto exit;
  81.     }
  82.     
  83.     if(!PrStlDialog(PrinterInfo))    // put up page setup dialog
  84.         goto exit;
  85.         
  86.     if((err = PrError()) != 0) {
  87.         ErrMsgCode("\p PrStlDialog failed.",err);
  88.         goto exit;
  89.     }
  90.     
  91.     if(!PrJobDialog(PrinterInfo))    // put up print dialog
  92.         goto exit;
  93.         
  94.     if((err = PrError()) != 0) {
  95.         ErrMsgCode("\p PrJobDialog failed.",err);
  96.         goto exit;
  97.     }
  98.  
  99.     // Install the idle proc
  100.     PrintIdleProcUPP = NewPrIdleProc((ProcPtr) PrintIdleProc);
  101.     SetCursor(*GetCursor(watchCursor));
  102.     (**PrinterInfo).prJob.pIdleProc = PrintIdleProcUPP;
  103.     
  104.     // Setup the print grafport
  105.     printPort = PrOpenDoc(PrinterInfo, nil, nil);
  106.     if((err = PrError()) != 0) {
  107.         ErrMsgCode("\p PrOpenDoc failed.",err);
  108.         goto exit;
  109.     }
  110.     
  111.     // Loop through these for page number of times
  112.     {
  113.         // Print a page
  114.         PrOpenPage(printPort, nil);
  115.         if((err = PrError()) != 0) {
  116.             ErrMsgCode("\p PrOpenPage failed.",err);
  117.             goto exit;
  118.         }
  119.         
  120.         /* Draw printing here Code here (draw in print port) */
  121.         
  122.         // Close the page
  123.         PrClosePage(printPort);
  124.         if((err = PrError()) != 0) {
  125.             ErrMsgCode("\p PrClosePage failed.",err);
  126.             goto exit;
  127.         }
  128.     }
  129.  
  130.     // Close the Printer
  131.     PrCloseDoc(printPort);
  132.     if((err = PrError()) != 0) {
  133.         ErrMsgCode("\p PrCloseDoc failed.",err);
  134.         goto exit;
  135.     }
  136.     
  137.     // Physically print the spooled print job
  138.     if( ((**PrinterInfo).prJob.bJDocLoop == bSpoolLoop))
  139.         PrPicFile( PrinterInfo, nil, nil, nil, &PrinterStat);
  140.  
  141.     if((err = PrError()) != 0) {
  142.         ErrMsgCode("\p PrPicFile failed.",err);
  143.         goto exit;
  144.     }
  145.     
  146. exit:
  147.     // Clean up and close the printer driver
  148.     PrClose();
  149.     if((err = PrError()) != 0)
  150.         ErrMsgCode("\p PrClose failed.",err);
  151.     
  152.     InitCursor();
  153.     
  154. } // PrintWindow